﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WorldEditor
{
    public partial class OptionBox : Form
    {
        public event ApplyEventHandler Apply;

        public OptionBox()
        {
            InitializeComponent();
        }
        public ResizeImage rSize
        {
            get
            {
                ResizeImage rImage = new ResizeImage();
                Size mapSize = Size.Empty;
                Size tileSize = Size.Empty;
                Size tileSetSize = Size.Empty;

                mapSize.Width = (int)numericUpDownMW.Value;
                mapSize.Height = (int)numericUpDownMH.Value;

                tileSize.Width = (int)numericUpDownTW.Value;
                tileSize.Height = (int)numericUpDownTH.Value;

                tileSetSize.Width = (int)numericUpDownTileSW.Value;
                tileSetSize.Height = (int)numericUpDownTileSH.Value;
                
                rImage.MSize = mapSize;
                rImage.TSize = tileSize;
                rImage.TSetSize = tileSetSize;
                rImage.Name = textBox1.Text;

                return rImage;

            }
            set
            {


                numericUpDownMW.Value = value.MSize.Width;
                numericUpDownMH.Value = value.MSize.Height;

                numericUpDownTW.Value = value.TSize.Width;
                numericUpDownTH.Value = value.TSize.Height;

                numericUpDownTileSW.Value = value.TSetSize.Width;
                numericUpDownTileSH.Value = value.TSetSize.Height;

                textBox1.Text = Name;
            }

        }
        public delegate void ApplyEventHandler(object sender, ApplyEventArgs e);

        public class ApplyEventArgs : EventArgs
        {
            public ResizeImage reSize = null;

            public ApplyEventArgs(ResizeImage reSize)
            {
                this.reSize = reSize;
            }
        }
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (Apply != null)
            {

                Apply(this, new ApplyEventArgs(rSize));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();


            if (DialogResult.OK == dlg.ShowDialog())
            {
                string[] name = dlg.FileName.Split('\\');
                ResizeImage rImage = new ResizeImage(new Bitmap(dlg.FileName), name[name.Length - 1]);
                //textBox2.Text = tSize.Width.ToString();
                //textBox3.Text = tSize.Height.ToString();
                textBox1.Text = rImage.Name.ToString();
              
            }
        }

    }
}
